package com.scrabbleMaster.lindo.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Expression {
	private Map<String, Float> variables = new HashMap<String, Float>();
	private Double limit;
	private char operator;
	private double constantValue = 0;
	private String name = "";
	private static char LESS_THAN = 'L';
	private static char GREATER_THAN = 'G';
	
	private Expression(String name) {
		this.name = name;
	}
	
	public static Expression named(String name) {
		return new Expression(name);
	}

	public Expression with(int i, String name) {
		//Validar q no exista, sino, sumarlas
		this.variables.put(name, Float.valueOf(i));
		return this;
	}

	public Expression lessThan(Double limit) {
		this.operator = LESS_THAN;
		this.limit = limit;
		return this;
	}

	public char getOperatorRepresentation() {
		return operator;
	}
	
	public Double getLimit() {
		return limit;
	}

	public int getNotInvolvedVarsQuantity(List<String> varNames) {
		int result = 0;
		for (String varName : varNames) {
			if (this.variables.get(varName) == null)
				result++;
		}
		return result;
	}

	public List<String> getInvolvedVarNames() {
		List<String> varNames = new ArrayList<String>(variables.keySet());
		Collections.sort(varNames);
		return varNames;
	}

	public double getCoeficientFor(String varName) {
		return this.variables.get(varName) == null ? 0 : this.variables.get(varName); 
	}

	public Expression with(double constantValue) {
		this.constantValue  = constantValue;
		return this;
	}

	public double getConstantValue() {
		return constantValue;
	}

	public Expression greaterThan(double limit) {
		this.operator = GREATER_THAN;
		this.limit = limit;
		return this;
	}

	public String getName() {
		return name ;
	}
	
	public void setName(String name) {
		this.name = name;
	}
}
